//
//  ZGLConfirmSelectView.m
//  ZeegingLottery
//
//  Created by 蒂埃里 on 2018/4/16.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLConfirmSelectView.h"


@interface ZGLConfirmSelectView ()

@property (strong ,nonatomic)UILabel *tipLablel;


@end

@implementation ZGLConfirmSelectView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = sRGBHexAlpha(0xFFFFFF, 1.0);
//        self.userInteractionEnabled = NO;
        
        [self addSubview:self.confirmBtn];
        [self addSubview:self.selectedLabel];
        [self addSubview:self.tipLablel];
        [self addSubview:self.cleanAllBtn];
        
        [self setupUI];
    }
    
    return self;
}

- (void)setSelectedNum:(NSInteger)selectedNum
{
    _selectedNum = selectedNum;
    self.selectedLabel.text = [NSString stringWithFormat:@"已选择 %ld 场",selectedNum];
    NSMutableAttributedString *strAtt = [[NSMutableAttributedString alloc] initWithString:self.selectedLabel.text];
    [strAtt addAttribute:NSForegroundColorAttributeName value:globalRed range:NSMakeRange(4,1)];
    self.selectedLabel.attributedText = strAtt;
    if (selectedNum>=2) {
        [self.confirmBtn setBackgroundColor:sRGBHexAlpha(0xF63F3F, 1.0)];
        [self.confirmBtn setUserInteractionEnabled:YES];
    }else{
        [self.confirmBtn setBackgroundColor:[UIColor lightGrayColor]];
        [self.confirmBtn setUserInteractionEnabled:NO];
    }
    
}

#pragma mark - getter

-(UIButton *)confirmBtn
{
    if (!_confirmBtn) {
        _confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_confirmBtn setTitle:@"选好了" forState:UIControlStateNormal];
        [_confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        [_confirmBtn setBackgroundColor:sRGBHexAlpha(0xF63F3F, 1.0)];
        [_confirmBtn setUserInteractionEnabled:NO];
        [_confirmBtn setBackgroundColor:[UIColor lightGrayColor]];
        _confirmBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        _confirmBtn.layer.cornerRadius = 5;
        _confirmBtn.layer.masksToBounds = YES;
        
        [_confirmBtn addTarget:self action:@selector(confirmBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _confirmBtn;
}


- (LSYButton *)cleanAllBtn
{
    if (!_cleanAllBtn) {
        _cleanAllBtn = [LSYButton buttonWithType:UIButtonTypeCustom];
        [_cleanAllBtn setLsyButtonStyle:LSYButtonStyleImageTitleVertical];
        [_cleanAllBtn setImage:[UIImage imageNamed:@"1_delete_top"] forState:UIControlStateNormal];
        [_cleanAllBtn setTitle:@"清空" forState:UIControlStateNormal];
        [_cleanAllBtn setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
        _cleanAllBtn.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelFontSize];
        [_cleanAllBtn setUpImageAndDownTitleByMargin:6];
        
        _cleanAllBtn.tag = 111;
//        [_cleanAllBtn addTarget:self action:@selector(cleanBtnClickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _cleanAllBtn;
}

- (UILabel *)selectedLabel
{
    if (!_selectedLabel) {
        _selectedLabel = [[UILabel alloc]init];
        _selectedLabel.textAlignment = 1;
        _selectedLabel.textColor = sRGBHexAlpha(0x333333, 1.0);
        _selectedLabel.font = [UIFont fontWithName:@"Arial" size:13];
        _selectedLabel.text = [NSString stringWithFormat:@"已选择 %ld 场",self.selectedNum];
        NSMutableAttributedString *strAtt = [[NSMutableAttributedString alloc] initWithString:_selectedLabel.text];
        [strAtt addAttribute:NSForegroundColorAttributeName value:globalRed range:NSMakeRange(4,1)];
        _selectedLabel.attributedText = strAtt;
    }
    
    return _selectedLabel;
}

- (UILabel *)tipLablel
{
    if (!_tipLablel) {
        _tipLablel = [[UILabel alloc]init];
        _tipLablel.textAlignment = 1;
        _tipLablel.textColor = sRGBHexAlpha(0x999999, 1.0);
        _tipLablel.font = [UIFont systemFontOfSize:btnFontSize];
        _tipLablel.text = @"请至少选择2场比赛";
    }
    
    return _tipLablel;
}


- (void)setupUI
{
    
    [HKUIUtils addLineInView:self color:BorderColor top:YES leftMargin:0 rightMargin:0];
    
    [_confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(5);
        make.right.equalTo(self).offset(-10);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(90);
    }];
    
    
    [_cleanAllBtn mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(self).offset(10);
        make.top.equalTo(_confirmBtn);
        make.bottom.equalTo(_confirmBtn);
        make.width.mas_equalTo(80);

    }];
    
    [_selectedLabel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(_cleanAllBtn.mas_right);
        make.right.equalTo(_confirmBtn.mas_left);
        make.top.equalTo(_confirmBtn);
    }];

    [_tipLablel mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.equalTo(_cleanAllBtn.mas_right);
        make.right.equalTo(_confirmBtn.mas_left);
        make.bottom.equalTo(_confirmBtn.mas_bottom);
    }];
}

#pragma mark - meth

- (void)confirmBtnClickAction:(UIButton *)sender
{
    if (self.confirmButtonClick) {
        self.confirmButtonClick(sender);
    }
    
}

- (void)cleanBtnClickAction:(UIButton *)sender;
{
    if (self.cleanButtonClick) {
        self.cleanButtonClick(sender, sender.tag);
    }
    
    
    
}


@end
